import Vue from "vue";
import Vuex from "vuex";
import userInfo from "./modules/userInfo";
import car from "./modules/car";
import createPersistedstate from "vuex-persistedstate";
Vue.use(Vuex);

export default new Vuex.Store({
    // 进行模块化,方便同事直接协同,好维护
    modules: {
        userInfo,
        car
    },
    plugins: [
        //持久化插件.因为vuex存储内存.刷新会消失,所以使用这个
        createPersistedstate({
            key: "userInfo", //存储的名字
            storage: window.sessionStorage, //存储的位置
            paths: ["car"], // 存储的是哪个模块,
            reducer: (state) => {
                //存储模块中具体的状态
                console.log("插件中", state);
                return { num: state.userInfo.num };
            }
        })
    ],

    strict: true
});
